import 'package:flutter/material.dart';

/// Opens an [AlertDialog] showing what the user typed.
class TestInputText extends StatefulWidget {
  TestInputText({Key key}) : super(key: key);

  @override
  _TestInputTextState createState() => new _TestInputTextState();
}

/// State for [TestInputText] widgets.
class _TestInputTextState extends State<TestInputText> {
  final TextEditingController _controller = new TextEditingController();

  @override
  Widget build(BuildContext context) {
    double fullSpace = MediaQuery.of(context).size.width * 0.01;
    double halfSpace = MediaQuery.of(context).size.width * 0.005;
    double fullWidth = MediaQuery.of(context).size.width * 0.98;
    double halfWidth = MediaQuery.of(context).size.width * 0.485;
    return Scaffold(
      appBar: AppBar(
        title: Text("文本输入"),
      ),
      body: new Builder(builder: (BuildContext context) => Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Row(
            children: <Widget>[
              Container(
                margin: EdgeInsets.fromLTRB(fullSpace, fullSpace, halfSpace, fullSpace),
                child: SizedBox(
                  width: halfWidth,
                  child: TextFormField(
                    decoration: InputDecoration(
                      prefixText: "姓名",
                      prefixStyle: TextStyle(color: Colors.black54),
                      hintText: "请输入姓名",
                      contentPadding: EdgeInsets.fromLTRB(8.0, 4.0, 8.0, 4.0),
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(2.0),
                      ),
                    ),
                    textAlign: TextAlign.right,
                  ),
                ),
              ),
              Container(
                margin: EdgeInsets.fromLTRB(halfSpace, fullSpace, fullSpace, fullSpace),
                child: SizedBox(
                  width: halfWidth,
                  child: TextFormField(
                    decoration: InputDecoration(
                      prefixText: "性别",
                      // prefixStyle: TextStyle(color: Colors.black54),
                      hintText: "请输入性别",
                      contentPadding: EdgeInsets.fromLTRB(8.0, 4.0, 8.0, 4.0),
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(2.0),
                      ),
                    ),
                    textAlign: TextAlign.right,
                  ),
                ),
              ),
            ],
          ),
          Row(
            children: <Widget>[
              Container(
                margin: EdgeInsets.fromLTRB(fullSpace, fullSpace, fullSpace, fullSpace),
                child: SizedBox(
                  width: fullWidth,
                  child: TextFormField(
                    decoration: InputDecoration(
                      prefixText: "地址",
                      prefixStyle: TextStyle(color: Colors.black54),
                      hintText: "请输入地址",
                      contentPadding: EdgeInsets.fromLTRB(8.0, 4.0, 8.0, 4.0),
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(2.0),
                      ),
                    ),
                    textAlign: TextAlign.right,
                  ),
                ),
              ),
            ],
          ),

          new TextField(
            controller: _controller,
            decoration: new InputDecoration(
              hintText: '请输入',
            ),
          ),
          new RaisedButton(
            onPressed: () {
              showDialog(
                context: context,
                builder: (context) {
                  return new AlertDialog(
                    title: new Text('What you typed'),
                    content: new Text(_controller.text),
                  );
                }
              );
            },
            child: new Text(' 完成 '),
          ),
        ],
      ),
      ),
    );
  }
}
